import static org.junit.Assert.*;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
import org.junit.Test;


public class TickCounterTest {

	TickCounter tc;
	ExecutorService exec;
	private static long CYCLES = 1_000_000;
	
	
	@Before
	public void setUp() throws Exception {
		tc = new TickCounter();
		exec = Executors.newFixedThreadPool(16);
	}

	@Test
	public void test() throws InterruptedException {
		for (int i = 0; i < CYCLES; ++i) {
			exec.execute(new Runnable() {
				@Override
				public void run() {
					tc.nextKey();
				}
			});
		}
		exec.shutdown();
		exec.awaitTermination(30, TimeUnit.SECONDS);
		assertEquals(tc.getCount(), CYCLES);
	}
	
}
